<?php
require('config.php');
        $time=time();
        $t1=strtotime(date('Y-m-d 00:00:00',$time));
        $t2=strtotime(date('Y-m-d 08:00:00',$time));
        $t3=strtotime(date('Y-m-d 12:00:00',$time));
        $t4=strtotime(date('Y-m-d 16:00:00',$time));
        $t5=strtotime(date('Y-m-d 20:00:00',$time));
        $t6=strtotime(date('Y-m-d 24:00:00',$time));
        $data[0]['pan']=-1;
        $isGoodsContent=0;
        if(isset($_REQUEST['isGoodsContent'])) $isGoodsContent=$_REQUEST['isGoodsContent'];
		if($time<$t2 && $time>=$t1)
		{
			$pan=1;
			$stat_time=$t1;
			$end_time=$t2;
		}
		if($time<$t3 && $time>=$t2)
		{
			$pan=2;
			$stat_time=$t2;
			$end_time=$t3;
		}
		if($time<$t4 && $time>=$t3)
		{
			$pan=3;
			$stat_time=$t3;
			$end_time=$t4;
		}
		if($time<$t5 && $time>=$t4)
		{
			$pan=4;
			$stat_time=$t4;
			$end_time=$t5;
		}
		if($time<$t6 && $time>=$t5)
		{
			$pan=5;
			$stat_time=$t5;
			$end_time=$t6;
		}
		$user_id=$_REQUEST['user_id'];
		$pan2=$pan-1;
        //$sql="select * from ".$oto."_goods,".$oto."_goods_seckill where ".$oto."_goods.isSeckill='1' and ".$oto."_goods.goodsId=".$oto."_goods_seckill.goodsId and ".$oto."_goods.shopId=".$oto."_goods_seckill.shopId and ".$oto."_goods_seckill.goodsSeckillStatus='1' and seckillStartTime>='{$stat_time}' and seckillEndTime<='{$end_time}' order by id DESC";
        $sql="select * from ".$oto."_goods,".$oto."_goods_seckill where ".$oto."_goods.isSeckill='1' and ".$oto."_goods.goodsId=".$oto."_goods_seckill.goodsId and ".$oto."_goods.shopId=".$oto."_goods_seckill.shopId and ".$oto."_goods_seckill.goodsSeckillStatus='1' and seckillStartTime<='{$time}' and seckillEndTime>'{$time}' and seckillSetTime='{$pan2}' and goodsStatus='1' order by id DESC";
        //file_put_contents("tsxx.txt", "\r\n".$sql."\r\n", FILE_APPEND);
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$goods_info[]=$row;//将取得的所有数据赋值给person_info数组
		}
		if(isset($goods_info))
		{
		for($i=0;$i<count($goods_info);$i++)
		{
			$goods_id=$goods_info[$i]['goodsId'];
			$seckillStartTime=$goods_info[$i]['seckillStartTime'];
			$seckillEndTime=$goods_info[$i]['seckillEndTime'];
			//$sql="select * from ".$oto."_orders,".$oto."_order_goods where ".$oto."_orders.orderId=".$oto."_order_goods.orderId and ".$oto."_order_goods.goodsId='{$goods_id}' and ".$oto."_orders.orderType='2' and payTime<'{$end_time}' and payTime>='{$stat_time}'";
			$sql="select * from ".$oto."_orders as o,".$oto."_order_goods as g where o.orderId=g.orderId and g.goodsId='{$goods_id}' and o.orderType='2' and payTime<'{$seckillEndTime}' and payTime>='{$seckillStartTime}'";
			$result=$db->query($sql);
			//file_put_contents("tsxx.txt", "\r\n1:".$sql."\r\n", FILE_APPEND);
			while($row=$result->fetch_assoc()){
				$xiaoliang_info[]=$row;//将取得的所有数据赋值给person_info数组
			}
			$sum=0;
			$sum2=0;
			if(!isset($user_id) || $user_id==0 || $user_id=='0')
			{
				$sum2=0;
			}
			else
			{
				//$sql="select * from ".$oto."_orders,".$oto."_order_goods where ".$oto."_orders.orderId=".$oto."_order_goods.orderId and ".$oto."_order_goods.goodsId='{$goods_id}' and ".$oto."_orders.orderType='2' and userId='{$user_id}' and payTime<'{$end_time}' and payTime>='{$stat_time}'";
				$sql="select * from ".$oto."_orders,".$oto."_order_goods where ".$oto."_orders.orderId=".$oto."_order_goods.orderId and ".$oto."_order_goods.goodsId='{$goods_id}' and ".$oto."_orders.orderType='2' and userId='{$user_id}' and payTime<'{$seckillEndTime}' and payTime>='{$seckillStartTime}'";
				$result=$db->query($sql);
				//file_put_contents("tsxx.txt", "\r\n2:".$sql."\r\n", FILE_APPEND);
				while($row=$result->fetch_assoc()){
					$user_xiaoliang_info[]=$row;//将取得的所有数据赋值给person_info数组
				}
				if(!isset($user_xiaoliang_info))
				{
					$sum2=0;
				}
				else
				{
					for($j=0;$j<count($user_xiaoliang_info);$j++)
					{
						$sum2+=$user_xiaoliang_info[$j]['goodsNums'];
					}
				}
			}
			if(!isset($xiaoliang_info))
			{
				$sum=0;
			}
			else
			{
				for($j=0;$j<count($xiaoliang_info);$j++)
				{
					$sum+=$xiaoliang_info[$j]['goodsNums'];
				}
			}
			$goods_info[$i]['goods_yimai']=$sum;
			$goods_info[$i]['user_yimai']=$sum2;
			$goods_info[$i]['time']=$time;
			if($isGoodsContent!=0) $goods_info[$i]['goodsDesc']="";

			$sql="select * from `".$oto."_goods_attributes`,`".$oto."_attributes` where ".$oto."_goods_attributes.goodsId='$goods_id' and isPriceAttr=1 and ".$oto."_goods_attributes.attrId=".$oto."_attributes.attrId order by ".$oto."_attributes.attrId ASC,".$oto."_goods_attributes.isRecomm DESC";
			$result=$db->query($sql);
			while($row=$result->fetch_assoc()){
				$isShuxing[]=$row;//将取得的所有数据赋值给person_info数组
			}
			if(isset($isShuxing)) $goods_info[$i]['isShuxing']=1;
			else $goods_info[$i]['isShuxing']=0;
		}
		}
		if(isset($goods_info)) echo json_encode($goods_info);
		else echo '[]';
?>